//
//  MVViewController.m
//  Temp
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 不二晶. All rights reserved.
//

#import "MVViewController.h"
#import "NetWorkingTool.h"
#import "UIImageView+WebCache.h"
#import "MVModel.h"
#import "MVCell.h"
#import "MVPlayViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface MVViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, retain)UITableView *MVTableView;
@property(nonatomic, retain)NSMutableArray *MVArr;
@end

@implementation MVViewController
- (void)dealloc
{
    [_MVArr release];
    [_MVTableView release];
    [super dealloc];
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.MVArr = [NSMutableArray array];
        self.title = @"MV";
    }
    [self MVDate];
    return self;
}
- (void)MVDate{
    [NetWorkingTool netWorkingToolStr:@"URL：http://v1.ard.tj.itlily.com/ttpod?a=getnewttpod&id=366&page=1&app=ttpod&v=v7.7.0.2015012818&uid=&mid=iPhone5C&f=f320&s=s310&imsi=&hid=&splus=8.0.2&active=1&net=2&openudid=5644dc238845c5739a5e37f08f22c51d938fc544&idfa=4331AEED-1B57-45FB-87C9-D9421ECD697F&utdid=VLoWmt5itKgDAPTY+A6pV5QN&alf=201200" block:^(id result) {
        NSMutableDictionary *dic = result;
        NSMutableArray *arr = [NSMutableArray array];
        arr = dic[@"data"];
        for (NSInteger i = 0; i < arr.count; i++) {
            MVModel *mv = [[MVModel alloc] init];
            [mv setValuesForKeysWithDictionary:arr[i]];
            [self.MVArr addObject:mv];
            [mv release];
        }
        [self.MVTableView reloadData];
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.MVTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:self.MVTableView];
    [_MVTableView release];
    
    self.MVTableView.delegate = self;
    self.MVTableView.dataSource = self;
    
}
#pragma mark 协议必须实现的方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.MVArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *reuse = @"reuse";
    MVCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (cell == nil) {
        cell = [[[MVCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
    }
    MVModel *mv = [[MVModel alloc] init];
    mv = self.MVArr[indexPath.row];
    cell.MVNameLabel.text = mv.mv_name;
    cell.singerLabel.text = mv.singer;
    NSURL *url = [NSURL URLWithString:mv.pic_url];
    [cell.picImageView sd_setImageWithURL:url];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MVPlayViewController *mvPlayVC = [[MVPlayViewController alloc] init];
    mvPlayVC.mvPassURL = [self.MVArr[indexPath.row] url_low];
    [self.navigationController pushViewController:mvPlayVC animated:YES];
    [mvPlayVC release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
